<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>vue</title>
		<script type="text/javascript" src="js/vue.js" ></script>
	</head>
	<body>
		<div id="root">
			<!--动态组件-->
			<!--<component :is="type"></component>-->
			
			<!--v-once:提高加载性能，只加载一次-->
        	<child-one v-if="type === 'child-one'"></child-one>
        	<child-two v-if="type === 'child-two'"></child-two>
        	<button @click="handleBtnClick">change</button>
        </div>
		
		<script>
			
			Vue.component("child-one", {
				template: "<div v-once>child-one</div>"
			})
			
			Vue.component("child-two", {
				template: "<div v-once>child-two</div>"
			})
			
			var vm = new Vue({
				el: '#root',
				data: {
					type: "child-one"
				},
				methods: {
					handleBtnClick: function() {
						this.type = (this.type === 'child-one') ? 'child-two' : 'child-one'
					}
				}
			})
			
		</script>
	</body>
</html>
